﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VCN.App.DataAccessLayer;
using VCN.App.DataTransferObjects;

namespace VCN.home.UC
{
    public partial class ContactUC : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void submit_contact_button(object sender, EventArgs e)
        {
            lblStatus_co.Text = "";
            if (check_fill_data())
            {
                ContactUsObject m_contact_obj = new ContactUsObject();
                m_contact_obj.Name = txtName.Text;
                m_contact_obj.Email = txtEmail.Text;
                m_contact_obj.Subject = txtSubject.Text;
                m_contact_obj.Message = txtMessage.Text;
                m_contact_obj.Datetime = DateTime.Now;
                ContactUsDAO.insert(m_contact_obj);
                lblStatus_co.Text = "Thank you for your contact.";
                null_data();
            }
            else
                lblStatus.Text = "You must enter full of information!";      
        }

        //Kiem tra xem da co du lieu tren cac truong chua
        protected bool check_fill_data()
        {
            if (txtName.Text.Equals("")
               || txtEmail.Text.Equals("")
                || txtMessage.Text.Equals("")
                || txtSubject.Text.Equals(""))
            {                
                return false;                  
            }
            else
            {                
                return true;                
            }
        }
        protected void null_data()
        {
            txtEmail.Text = "";
            txtMessage.Text = "";
            txtName.Text = "";
            txtSubject.Text = "";
        }
    }
}